package com.mysterymall.Controller.Admin;

import com.mysterymall.Common.Comp.HttpStatus;
import com.mysterymall.Common.Comp.Log;
import com.mysterymall.Common.Utils.Result;
import com.mysterymall.Model.Dto.TeamDto;
import com.mysterymall.Service.TeamService;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName com.mysterymall.Controller.Admin
 * @Description
 * @Author HuangWX
 * @Time 2023/12/02  13:56
 */
@RestController
@RequestMapping("/team")
public class AdminTeamController {


    private final TeamService teamService;

    /**
     * 构造器注入
     * @param teamService 团队服务
     */
    public AdminTeamController(TeamService teamService) {
        this.teamService = teamService;
    }

    /**
     * 获取团队列表
     *
     * @param page 页码
     * @param size 每页数量
     * @return Result
     */
    @GetMapping("/getTeamList")
    @Log
    public Result getTeamList(@RequestParam(value = "page", defaultValue = "0") Integer page,
                              @RequestParam(value = "size", defaultValue = "0") Integer size) {
        // 校验参数
        if (page < 0 || size < 0) {
            return new  Result(HttpStatus.BAD_REQUEST, "参数错误");
        }
        return teamService.getTeamList(page, size);
    }

    /**
     * 更新团队
     *
     * @param teamDto 团队信息
     * @return Result
     */
    @PostMapping("/updateTeam")
    @Log
    public Result updateTeam(@RequestBody TeamDto teamDto) {
        return teamService.updateTeam(teamDto);
    }

    /**
     * 获取团队详情
     * @param id 团队id
     * @return Result
     */
    @GetMapping("/getTeamInfo")
    @Log
    public Result getTeamInfo(@RequestParam(value = "id") String id, @RequestParam(value = "currIndex", defaultValue = "0") Integer page,
                              @RequestParam(value = "pageSize", defaultValue = "0") Integer size) {
        return teamService.getTeamInfo(id, page, size);
    }

}
